From dd7c0d77b1e8558e11e318e5bda8107c7609d4a9 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Thu, 1 Dec 2005 20:49:17 +0000 Subject: [PATCH] Merged modified patch from maemo-gtk that allows to disable toolbar 2005-12-01 Michael Natterer Merged modified patch from maemo-gtk that allows to disable toolbar animations. Addresses bug #142582. * gtk/gtksettings.c: added boolean property "gtk-enable-animations". (patch from Christian Neumair) * gtk/gtktoolbar.c: don't animate toolbar changes if the settings property is FALSE. Replaced the individual "notify::foo" connections to GtkSettings by a single "notify" callback and dispatch internally. --- ChangeLog | 13 ++++++ ChangeLog.pre-2-10 | 13 ++++++ gtk/gtksettings.c | 13 +++++- gtk/gtktoolbar.c | 111 +++++++++++++++++++++++++++++---------------- 4 files changed, 110 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 510931ef04..81476aa168 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2005-12-01 Michael Natterer + + Merged modified patch from maemo-gtk that allows to disable + toolbar animations. Addresses bug #142582. + + * gtk/gtksettings.c: added boolean property "gtk-enable-animations". + (patch from Christian Neumair) + + * gtk/gtktoolbar.c: don't animate toolbar changes if the settings + property is FALSE. Replaced the individual "notify::foo" + connections to GtkSettings by a single "notify" callback and + dispatch internally. + 2005-12-01 Michael Natterer * gtk/gtkmenu.c (gtk_menu_class_init): removed redundant diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 510931ef04..81476aa168 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,16 @@ +2005-12-01 Michael Natterer + + Merged modified patch from maemo-gtk that allows to disable + toolbar animations. Addresses bug #142582. + + * gtk/gtksettings.c: added boolean property "gtk-enable-animations". + (patch from Christian Neumair) + + * gtk/gtktoolbar.c: don't animate toolbar changes if the settings + property is FALSE. Replaced the individual "notify::foo" + connections to GtkSettings by a single "notify" callback and + dispatch internally. + 2005-12-01 Michael Natterer * gtk/gtkmenu.c (gtk_menu_class_init): removed redundant diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c index 15b9f45f03..40a24b0cc9 100644 --- a/gtk/gtksettings.c +++ b/gtk/gtksettings.c @@ -85,7 +85,8 @@ enum { PROP_SHOW_UNICODE_MENU, PROP_TIMEOUT_INITIAL, PROP_TIMEOUT_REPEAT, - PROP_COLOR_SCHEME + PROP_COLOR_SCHEME, + PROP_ENABLE_ANIMATIONS }; @@ -458,6 +459,16 @@ gtk_settings_class_init (GtkSettingsClass *class) NULL); g_assert (result == PROP_COLOR_SCHEME); + + result = settings_install_property_parser (class, + g_param_spec_boolean ("gtk-enable-animations", + P_("Enable Animations"), + P_("Whether to enable toolkit-wide animations."), + TRUE, + GTK_PARAM_READWRITE), + NULL); + + g_assert (result == PROP_ENABLE_ANIMATIONS); } static void diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c index 760970d4f0..a40aa3b458 100644 --- a/gtk/gtktoolbar.c +++ b/gtk/gtktoolbar.c @@ -67,6 +67,7 @@ typedef struct _ToolbarContent ToolbarContent; #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH +#define DEFAULT_ANIMATION_STATE TRUE #define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate * in the homogeneous game. In units of @@ -143,13 +144,13 @@ struct _GtkToolbarPrivate GTimer * timer; - gulong style_set_connection; - gulong icon_size_connection; + gulong settings_connection; - guint show_arrow : 1; - guint need_sync : 1; - guint is_sliding : 1; - guint need_rebuild : 1; /* whether the overflow menu should be regenerated */ + guint show_arrow : 1; + guint need_sync : 1; + guint is_sliding : 1; + guint need_rebuild : 1; /* whether the overflow menu should be regenerated */ + guint animation : 1; }; static void gtk_toolbar_init (GtkToolbar *toolbar); @@ -658,7 +659,7 @@ gtk_toolbar_class_init (GtkToolbarClass *klass) GTK_TYPE_ICON_SIZE, DEFAULT_ICON_SIZE, GTK_PARAM_READWRITE)); - + binding_set = gtk_binding_set_by_class (klass); add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT); @@ -698,6 +699,7 @@ gtk_toolbar_init (GtkToolbar *toolbar) toolbar->orientation = GTK_ORIENTATION_HORIZONTAL; toolbar->style = DEFAULT_TOOLBAR_STYLE; toolbar->icon_size = DEFAULT_ICON_SIZE; + priv->animation = DEFAULT_ANIMATION_STATE; toolbar->tooltips = gtk_tooltips_new (); g_object_ref_sink (toolbar->tooltips); @@ -1040,10 +1042,16 @@ gtk_toolbar_size_request (GtkWidget *widget, } static gint -position (gint from, gint to, gdouble elapsed) +position (GtkToolbar *toolbar, + gint from, + gint to, + gdouble elapsed) { gint n_pixels; + if (! GTK_TOOLBAR_GET_PRIVATE (toolbar)->animation) + return to; + if (elapsed <= ACCEL_THRESHOLD) { n_pixels = SLIDE_SPEED * elapsed; @@ -1058,7 +1066,7 @@ position (gint from, gint to, gdouble elapsed) n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed - SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD; } - + if (to > from) return MIN (from + n_pixels, to); else @@ -1073,13 +1081,15 @@ compute_intermediate_allocation (GtkToolbar *toolbar, { GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); gdouble elapsed = g_timer_elapsed (priv->timer, NULL); - - intermediate->x = position (start->x, goal->x, elapsed); - intermediate->y = position (start->y, goal->y, elapsed); - intermediate->width = - position (start->x + start->width, goal->x + goal->width, elapsed) - intermediate->x; - intermediate->height = - position (start->y + start->height, goal->y + goal->height, elapsed) - intermediate->y; + + intermediate->x = position (toolbar, start->x, goal->x, elapsed); + intermediate->y = position (toolbar, start->y, goal->y, elapsed); + intermediate->width = position (toolbar, start->x + start->width, + goal->x + goal->width, + elapsed) - intermediate->x; + intermediate->height = position (toolbar, start->y + start->height, + goal->y + goal->height, + elapsed) - intermediate->y; } static void @@ -1990,33 +2000,63 @@ gtk_toolbar_focus (GtkWidget *widget, return result; } +static GtkSettings * +toolbar_get_settings (GtkToolbar *toolbar) +{ + GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); + return priv->settings; +} + static void style_change_notify (GtkToolbar *toolbar) { if (!toolbar->style_set) { /* pretend it was set, then unset, thus reverting to new default */ - toolbar->style_set = TRUE; + toolbar->style_set = TRUE; gtk_toolbar_unset_style (toolbar); } } static void icon_size_change_notify (GtkToolbar *toolbar) -{ +{ if (!toolbar->icon_size_set) { /* pretend it was set, then unset, thus reverting to new default */ - toolbar->icon_size_set = TRUE; + toolbar->icon_size_set = TRUE; gtk_toolbar_unset_icon_size (toolbar); } } -static GtkSettings * -toolbar_get_settings (GtkToolbar *toolbar) +static void +animation_change_notify (GtkToolbar *toolbar) { GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); - return priv->settings; + GtkSettings *settings = toolbar_get_settings (toolbar); + gboolean animation; + + if (settings) + g_object_get (settings, + "gtk-enable-animations", &animation, + NULL); + else + animation = DEFAULT_ANIMATION_STATE; + + priv->animation = animation; +} + +static void +settings_change_notify (GtkSettings *settings, + const GParamSpec *pspec, + GtkToolbar *toolbar) +{ + if (! strcmp (pspec->name, "gtk-toolbar-style")) + style_change_notify (toolbar); + else if (! strcmp (pspec->name, "gtk-toolbar-icon-size")) + icon_size_change_notify (toolbar); + else if (! strcmp (pspec->name, "gtk-enable-animations")) + animation_change_notify (toolbar); } static void @@ -2038,33 +2078,26 @@ gtk_toolbar_screen_changed (GtkWidget *widget, if (old_settings) { - g_signal_handler_disconnect (old_settings, priv->style_set_connection); - g_signal_handler_disconnect (old_settings, priv->icon_size_connection); + g_signal_handler_disconnect (old_settings, priv->settings_connection); g_object_unref (old_settings); } - + if (settings) { - priv->style_set_connection = - g_signal_connect_swapped (settings, - "notify::gtk-toolbar-style", - G_CALLBACK (style_change_notify), - toolbar); - priv->icon_size_connection = - g_signal_connect_swapped (settings, - "notify::gtk-toolbar-icon-size", - G_CALLBACK (icon_size_change_notify), - toolbar); - - g_object_ref (settings); - priv->settings = settings; + priv->settings_connection = + g_signal_connect (settings, "notify", + G_CALLBACK (settings_change_notify), + toolbar); + + priv->settings = g_object_ref (settings); } else priv->settings = NULL; - + style_change_notify (toolbar); icon_size_change_notify (toolbar); + animation_change_notify (toolbar); } static int -- 2.30.2